import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:ride_rex/main/mine/block_list/block_bean.dart';
import 'package:ride_rex/main/mine/block_list/mine_block_list_logic.dart';
import 'package:ylm_ui_kit/ylm_ui_kit.dart';

class MineBlockListPage extends GetView<MineBlockListLogic> {
  const MineBlockListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MineBlockListLogic>(
      init: MineBlockListLogic(),
      builder: (logic) {
        return BaseScaffold(
          titleStr: 'Blocked List',
          scaffoldBackgroundColor: Colors.white,
          child: ListView.separated(
            itemBuilder: (BuildContext context, int index) => MineBlockListItem(logic.blockList[index]),
            separatorBuilder: (BuildContext context, int index) => const SizedBox(),
            itemCount: logic.blockList.length,
          ),
        );
      },
    );
  }
}

class MineBlockListItem extends StatelessWidget {
  const MineBlockListItem(this.bean, {super.key});

  final BlockListBean bean;

  @override
  Widget build(BuildContext context) {
    return CommonListItemScaffold(
      contentPadding: EdgeInsets.symmetric(horizontal: 21.w, vertical: 16.w),
      left: _buildAvatar(),
      center: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildName(),
          _buildAge().paddingTop(8.w),
        ],
      ).paddingHorizontal(10.w).expanded(),
      right: _buildUnblock(),
    );
  }

  Widget _buildAvatar() {
    return ImageWidget.url(bean.avatar ?? '', width: 44.w, height: 44.w, radius: 44.w);
  }

  Widget _buildName() {
    return TextWidget.oneLine(text: bean.nickName, fontSize: 14, color: '#404040'.toColor);
  }

  Widget _buildAge() {
    return TextWidget.oneLine(
      text: '${bean.age} ${bean.registerCountry}',
      fontSize: 12,
      color: Colors.black.withOpacity(0.6),
    );
  }

  Widget _buildUnblock() {
    return ButtonWidget.text(
      'Unblock',
      alignment: Alignment.center,
      height: 26.w,
      width: 71.w,
      fontSize: 12,
      textColor: Colors.white,
      backgroundColor: '#454545'.toColor,
      onTap: () {
        Get.find<MineBlockListLogic>().unblock(bean.broadcasterId ?? '');
      },
      hasInkWell: false,
      borderRadius: 26.w,
    );
  }
}
